<template>
  <div class="add_channels_wrap">
    <el-button type="text" size="small" @click="showPlay">自由切分</el-button>
    <el-dialog
      v-if="pop_show"
      :title="dialogTitle"
      :visible.sync="pop_show"
      :close-on-click-modal="false"
      append-to-body
    >
      <div v-if="show">正在为您切分，请稍稍等待哦！</div>
      <el-form :inline="true">
        <el-form-item>
          <el-time-picker
            v-model="times"
            format="HH:mm:ss"
            value-format="HH:mm:ss"
            is-range
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            placeholder="请选择范围"
            :clearable="false"
          ></el-time-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" size="small" @click="docut()">
            开始切分
          </el-button>
        </el-form-item>
      </el-form>
      <el-row :gutter="20">
        <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
          <vab-player-mp4 :config="config" @player="Player = $event" />
        </el-col>
      </el-row>
    </el-dialog>
  </div>
</template>

<script>
  import { VabPlayerMp4 } from '@/plugins/vabPlayer.js'
  import { customcut } from '@/api/videos'

  export default {
    name: 'Player',
    components: {
      VabPlayerMp4,
    },
    props: {
      id: {
        type: Number,
        default: 0,
      },
      url: {
        type: String,
        default: '',
      },
      title: {
        type: String,
        default: '',
      },
    },

    data() {
      return {
        show: false,
        dialogTitle: this.$props.title,
        times: ['00:00:00', '00:01:30'],
        pop_show: false,
        Player: null,
        config: {
          id: 'mse2',
          url: this.$props.url,
          volume: 1,
          autoplay: false,
        },
        videoid: this.$props.id,
      }
    },
    mounted() {},
    methods: {
      showPlay() {
        this.pop_show = true
      },
      test() {
        console.log(this.times)
      },
      async docut() {
        let paytime = {
          startTime: '',
          endTime: '',
          id: 0,
        }
        this.show = true
        paytime.id = this.$props.id
        paytime.startTime = this.times[0]
        paytime.endTime = this.times[1]
        const { msg } = await customcut(paytime)
        this.show = false
        await this.$router.push({
          path: '/videoDetail',
          query: { id: this.videoid },
        })
      },
    },
  }
</script>
